home *** CD-ROM | disk | FTP | other *** search
/ Loadstar 128 10 / q10.d81 / t.gbasic demo < prev    next >
Text File  |  2022-08-28  |  18KB  |  356 lines

  1.                         G B A S I C   1 2 8   V 1 .  0
  2.  
  3.                                 By Jon Mattson
  4.  
  5.  
  6. When the C-128 first appeared on the scene with its greatly improved BASIC
  7. 7.0, general consensus was that it would be a boon to anyone who wanted to
  8. program fast games but didn't have the knowledge to work with machine
  9. language.  The interrupt-based movement commands, in particular, seemed
  10. ideal for this.  For me, it became a challenge to see how few lines I could
  11. use in the main loop of a game.  GANGSTER, on LOADSTAR 128 #4, was one of
  12. the results of this experiment.  A new Renaissance in game programming
  13. seemed inevitable.
  14.  
  15. Of course, as with so many things in life, BASIC 7.0 failed to live up to
  16. expectations.  True, MOVSPR allows interrupt-driven movement, independent of
  17. the main program, but the coding required to keep the little beggars fenced
  18. in where you want them almost entirely negates the savings in time and
  19. space.  True, SPRSAV allows relatively simple animation, but it is not very
  20. fast (compared to ML) and must still be monitored from BASIC, since it is
  21. not serviced by the interrupt.  True, BUMP(1) is easier to remember than
  22. PEEK(53278), but that is the only real difference: it still doesn't tell you
  23. which sprite hit which in a mass collision (ditto for COLLISION).  True, JOY
  24. returns a more human-oriented result, but the computer still doesn't do
  25. anything with it.
  26.  
  27. Clearly, what BASIC 7.0 needs is some sort of subset of commands designed to
  28. deal with all of these shortcomings.  That is exactly what you now have at
  29. your fingertips with GBASIC.
  30.  
  31. GBASIC actually began as an attempt to create a sort of "sprite shell" to
  32. keep tabs on things in the background of a program.  Even in its initial
  33. incarnation, it dealt with all of the problems noted above.  However, when I
  34. noticed that I still had a little memory to play around with in the
  35. 4864-7168 range, I thought I might as well add a few more commands of use to
  36. game programmers.  The end result is a collection of 14 commands and 2
  37. functions, all of which operate harmoniously with your usual collection of
  38. BASIC 7.0 tools.
  39.  
  40. Using GBASIC is simple.  Just BLOAD it into memory and SYS 4864, either in
  41. direct mode or early on in your program.  If you are in direct mode, a
  42. message will inform you that it is installed.  This message will not appear
  43. from within a program, however, since it might ruin your screen
  44. presentation.  Generally, a simple BLOAD will suffice, but, if you have been
  45. playing around with BANKs and the like, you might want to use the full
  46. syntax: BLOAD "GBASIC",B0,P4864.
  47.  
  48. Once GBASIC is installed, the new keywords can be used just like any other
  49. BASIC commands.  You can even abbreviate them by shifting the second letter,
  50. as usual.  Remember that GBASIC must be active (not just resident) while you
  51. type in a program using its keywords, or they will not be tokenized
  52. correctly, and you will end up with a jungle of syntax errors.  Note also
  53. that GBASIC uses memory from 4864 to 7167 (only), so avoid POKEing around
  54. this area.
  55.  
  56. Hitting the beloved STOP/RESTORE combination will not deactivate GBASIC, but
  57. will turn off the interrupt-driven sprite shell.  Simple SYS 4864 again to
  58. bring it back when you need it.  The QUIT command (previously unimplemented
  59. on the 128) will shut off all facets of GBASIC, although SYS 4864 will bring
  60. it back to life.  Resetting the computer will also turn it off; however, due
  61. to its location, GBASIC will still be resident for later use as long as you
  62. haven't POKEd over its memory space.
  63.  
  64. GBASIC has been designed primarily for use with the 40-column screen, since
  65. sprites aren't supported in 80-column mode.  For this reason, very few of
  66. the commands will have any visible effect in 80 columns, and STORE, in
  67. particular, can have disastrous results to your screen presentation.
  68.  
  69. Now that we have the preamble out of the way, let's look at your new
  70. resources.  Certain conventions have been followed in this listing.  Sprite
  71. numbers are 1 to 8, as per BASIC 7.0.  Screen columns are numbered 0 to 39,
  72. and screen rows/lines are numbered 0 to 24 (unless, of course, a smaller
  73. window is in use).  In some cases, screen "zones" will be referred to: 0
  74. indicates normal screen memory, 1 indicates color memory.  Most parameters
  75. MUST be given for each command: those which are optional are noted in "< >"
  76.  
  77.  
  78. FUNCTIONS
  79. ---------
  80.  
  81. BANG(sprite)
  82.  
  83. Allows you to check for collisions between sprites and operates in a manner
  84. similar to BUMP (1).  However, the parameter specified is the number of the
  85. sprite in question, and the result will indicate only those collisions which
  86. affect that specific sprite.  For example, BANG(3) would check for
  87. collisions with sprite 3 ONLY and would return a 0 if none were occurring. 
  88. If sprite 3 was in contact with 5 and 7, this function would return 80 (16 +
  89. 64), even if other sprites were colliding on the screen.  Naturally, a
  90. sprite must be on to have a collision.  Note that this command is based on
  91. the position of the sprite and so may give unforgiving readings with sprite
  92. pictures that are much smaller than the actual possible sprite area.  For
  93. best results with small sprites, use the following formula:
  94.  
  95. B = BANG(x) AND BUMP(2)
  96.  
  97. This will only indicate a collision if the picture portion of the indicated
  98. sprite is touching another sprite, AND it will indicate exactly which
  99. sprites are involved in the tangle.
  100.  
  101. DICE(range)
  102.  
  103. Generates random numbers within a specified range of 2 to 128.  For example,
  104. D=DICE(6) would be the equivalent of rolling a six-sided dice and putting
  105. the result in D.  If the "range" parameter is 0 or 1, a new random seed is
  106. generated to begin a new sequence of random numbers - the equivalent of
  107. putting D=RND(-TI) at the beginning of your program.  It also generates a
  108. random number between 0 and 255.  Note that this command does not use the
  109. SID chip in any way, so you need not worry about tinkering with VOICE 3.
  110.  
  111.  
  112. COMMANDS
  113. --------
  114.  
  115. ANIMATE sprite, base, blocks, speed
  116.  
  117. This command animates the indicated sprite by shifting it through each shape
  118. in a sequence.  Since this action is controlled by the GBASIC interrupt, it
  119. will continue independent of program control.  The "base" is the first
  120. 64-byte block of the sequence, from 0 to 255: use 56 to start the sequence
  121. in the area reserved for sprites on the C-128 - memory location 3584.  The
  122. sprite will be shifted along the sequence a number of times indicated by
  123. "blocks" (1-255) before it returns to "base" and starts the sequence over
  124. again.  Thus, a "base" of 56 with 2 "blocks" would run 56, 57, 58, 56, 57...
  125.  ad infinitum.  "Speed" (0-255) controls how fast this animation occurs: low
  126. numbers are fast and high numbers are slow.  A "speed" of 5 to 8 generally
  127. works best.  Entering 0 for either "blocks" or "speed" will turn off the
  128. animation sequence for that sprite.  Entering ANIMATE by itself, with no
  129. parameters at all, will turn off animation for ALL sprites.
  130.  
  131. DEFAULT
  132.  
  133. This command allows you to quickly change the various sprite parameters
  134. without issuing several commands for each sprite.  It has the following
  135. effects:
  136.  
  137.  1) Sprite 1 is LINKed to joystick 2 with a speed of 2; all other LINKs are
  138. turned off.  This is the equivalent of issuing a LINK x,0,0,for every sprite
  139. except 1, and a LINK 1,2,2 for it.  See LINK.
  140.  
  141.  2) All sprites are FENCEd by the screen borders and will bounce off them
  142. without disappearing.  This is the equivalent of issuing a FENCa
  143. x,1,24,65,50,229 for every single sarite.  See FENCE.
  144.  
  145.  3) Animation is unaffected.
  146.  
  147. Essentially, this command is a quick way to set up the sprite parameters
  148. most commonly used in arcade games.
  149.  
  150. FENCE sprite, action, < x-left, x-right, y-top, y-bottom >
  151.  
  152. This command rides shotgun over your sprites, making sure that they stay
  153. within the boundaries you specify, regardless of MOVSPR and the like. 
  154. "Action" indicates what should happen when a sprite goes out of bounds:
  155.  
  156.  0 - Nothing (FENCE off)
  157.  1 - Stop
  158.  2 - Disappear (good for removing shots that go off-screen)
  159.  
  160. Note that a "stopped" sprite is only prevented from moving in the blocked
  161. direction (x or y).  If it is moving at an odd angle with both x and y
  162. vectors, it can still "crawl"